package hanshi_interface;

/**
 * @author ChenYongHao
 * @date 2023/5/4 9:13
 * @desc 函数式接口作为方法的参数
 */
public class interfaceMethods {
    public static void main(String[] args) {
        // 匿名内部类的方式
        startThread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "线程启动了");
            }
        });
        // Lambda表达式方式
        startThread(() -> System.out.println(Thread.currentThread().getName() + "线程启动了"));
    }

    private static void startThread(Runnable r) {
        new Thread(r).start();
    }
}
